package lib.quasar.widget.photo;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import lib.quasar.widget.R;

/**
 * description: 全屏显示
 * created by kalu on 2018/4/20 10:18
 */
public final class PhotoDialog extends Dialog {

    private OnBackPressedListener listener;

    public PhotoDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

//        final ViewGroup root = findViewById(android.R.id.content);
//        final int resourceId = getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
//        final int statusBarHeight = getContext().getResources().getDimensionPixelSize(resourceId);
//        root.setPadding(0, statusBarHeight, 0, 0);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

        super.onCreate(savedInstanceState);
    }

    @Override
    public void show() {

        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));
        final Window window = getWindow();
        final WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.MATCH_PARENT; //注意一定要是MATCH_PARENT
        window.setAttributes(lp);

        super.show();
    }

    @Override
    public void onBackPressed() {

        if (null != listener) {
            listener.onBackPressed();
        } else {
            super.onBackPressed();
        }
    }

    public void setOnBackPressedListener(OnBackPressedListener listener) {
        this.listener = listener;
    }

    public interface OnBackPressedListener {
        void onBackPressed();
    }
}
